package com.situ.mall.controller;

import com.situ.mall.pojo.OrderItem;
import com.situ.mall.pojo.query.OrderQuery;
import com.situ.mall.service.IOrderService;
import com.situ.mall.util.LayUITableResult;
import com.situ.mall.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @RequestMapping("/getOrderListPage")
    public String getOrderListPage() {
        return "order_list";
    }

    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(OrderQuery orderQuery) {
        return orderService.selectByPage(orderQuery);
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public Result deleteById(Long orderNo) {
        boolean isSuccess = orderService.deleteById(orderNo);
        return isSuccess ? Result.ok("删除成功") : Result.error("删除失败");
    }

    @RequestMapping("/deleteAll")
    @ResponseBody
    public Result deleteAll(Long[] orderNoes) {
        boolean isSuccess = orderService.deleteAll(orderNoes);
        return isSuccess ? Result.ok("删除成功") : Result.error("删除失败");
    }

    @RequestMapping("/getCheckPage")
    public String getCheckPage(String orderNo, Model model) {
        System.out.println(orderNo);
        model.addAttribute("checkOrderNo", orderNo);
        return "order_item_list";
    }

    @RequestMapping("/selectByOrderNo")
    @ResponseBody
    public LayUITableResult selectByOrderNo(OrderQuery orderQuery) {
        return orderService.checkByOrderNo(orderQuery);
    }

    @RequestMapping("/updatePostage")
    @ResponseBody
    public Result updatePostage(Long orderNo, Integer postage) {
        boolean isSuccess = orderService.updatePostage(orderNo, postage);
        return isSuccess ? Result.ok("更新成功") : Result.error("更新失败");
    }
}
